import uiautomation
import pyautogui
class zhuyuanshoushutuiyao():
        his = uiautomation.WindowControl(searchDepth=1, Name='科玛奇医院信息管理系统')  # 锁定窗口
        his.SetFocus()

        #状态
        zhuangtai = his.ComboBoxControl( ClassName='ComboBox',foundIndex=1)
        daituiyao = zhuangtai.ListItemControl(Name='[0, 待退药]')
        yituiyao = zhuangtai.ListItemControl(Name='[1, 已退药]')

        #药房
        yaofang1 = his.ComboBoxControl(ClassName='ComboBox',foundIndex=2)
        yaofang2 = yaofang1.ListItemControl(Name='药房(4007)')
        cailiaofang = yaofang1.ListItemControl(Name='材料房(333336)')

        #病区
        bingqu = his.ComboBoxControl(ClassName='ComboBox',foundIndex=3)
        quanbu = bingqu.ListItemControl(Name='全部()')


        chaxun = his.ButtonControl( ClassName='Button',Name='查询')
        tuiyao = his.ButtonControl( ClassName='Button',Name='退药')
        huanzhexuanxiangka = his.TabItemControl(ClassName='TabItem',Name='患者')
        shujuwangge = huanzhexuanxiangka.DataGridControl(AutomationId='dgHZList')
        shuju = shujuwangge.DataItemControl(ClassName='DataGridRow',Name='Ksy.ChssClient.Access.Model.ZY_YZTYSQD')
        #点击住院患者的待退药
        def click_sj(self,name):
                all_shuju = self.shujuwangge.GetChildren()
                for i in all_shuju:
                        xm = i.GetFirstChildControl().GetNextSiblingControl().GetNextSiblingControl()
                        BT = i.GetFirstChildControl().GetNextSiblingControl()
                        if xm.Name == name:
                                BT.Click()

        #系统提示窗口
        xitongtishichuangkou = his.WindowControl(ClassName='Window')
        queding = xitongtishichuangkou.ButtonControl(AutomationId='YesBtn', ClassName='Button',Name='是')
        quxiao = xitongtishichuangkou.ButtonControl(AutomationId='NoBtn', ClassName='Button',Name='否')
        guanbi = xitongtishichuangkou.ButtonControl(AutomationId='btn_Close', ClassName='Button',Name='关闭')






        #选择未发药
        def choose_dty(self):
                self.zhuangtai.Click()
                self.daituiyao.Click()
        #选择已发药
        def choose_yty(self):
                self.zhuangtai.Click()
                self.yituiyao.Click()

        #选择药房
        def choose_yf(self):
                self.yaofang1.Click()
                self.yaofang2.Click()
        #选择材料房
        def choose_clf(self):
                self.yaofang1.Click()
                self.cailiaofang.Click()

        #选择病区
        def choose_bq(self):
                self.bingqu.Click()
                self.quanbu.Click()

        #点击查询按钮
        def click_cx_btn(self):
                self.chaxun.Click()
        #点击患者选项卡
        def click_hz(self,name):
                self.huanzhexuanxiangka.Click()
                self.huanzhexuanxiangka.Refind()
                self.shujuwangge.Refind()
                all_shuju = self.shujuwangge.GetChildren()
                for i in all_shuju:
                        xm = i.GetFirstChildControl().GetNextSiblingControl().GetNextSiblingControl()
                        BT = i.GetFirstChildControl().GetNextSiblingControl()
                        if xm.Name == name:
                                BT.Click()


        #点击发药
        def clicl_ty_btn(self):
                self.tuiyao.Click()

        #点击提示确定按钮
        def click_tsqd_btn(self):
                self.xitongtishichuangkou.Refind()
                self.queding.Refind()
                self.queding.Click()
        #点击提示取消按钮
        def click_tsqx_btn(self):
                self.xitongtishichuangkou.Refind()
                self.quxiao.Refind()
                self.quxiao.Click()
        #点击提示关闭按钮
        def click_tsgb_btn(self):
                self.xitongtishichuangkou.Refind()
                self.guanbi.Refind()
                self.guanbi.Click()

















